<!---

Copyright 2008:

Author: Marco van den Oever
Company: WSO
Website: http://www.webserviceonline.biz
Email: marco@webserviceonline.biz

License: 

This software is licensed under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
For a copy of the GNU General Public License check the license folder or see <http://www.gnu.org/licenses/>.

Description:

wsoFarcryTickets, a Farcry plugin to administer tickets

Build with great support from the Farcry-Dev group! (Google on Farcry-Dev)

Created: 29/11/08

Tested on CF8

--->
<cfsetting enablecfoutputonly="true">
<cfimport taglib="/farcry/core/tags/formtools" prefix="ft" />
<cfimport taglib="/farcry/core/tags/admin/" prefix="admin" />
<!--- set up page header --->
<admin:header title="Tickets" />
<!--- check if the ticketanswer type is deployed, else show link to deploy --->

<cftry>
  <cfquery name="ticketanswercheck" datasource="#application.dsn#">
  SELECT objectid FROM #application.dbowner#ticketanswers WHERE objectid = objectid
  </cfquery>
  <cfcatch type="any">
    <cfoutput>The 'Ticketanswers' content type has not been deployed yet. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/ticketanswers.cfm&amp;plugin=wsoFarcryTickets&amp;deploy=true">here</a> to deploy it now.</cfoutput>
    <cfabort>
  </cfcatch>
</cftry>
<!--- check if the departments type is deployed, else show link to deploy --->
<cftry>
  <cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
  <cfset sqlColumns="objectid" />
  <cfset knbase = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="objectid = objectid", typename="departments",
bCheckVersions=true) />
  <cfcatch type="database">
    <cfoutput>The 'Departments' content type has not been deployed yet. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/departments.cfm&amp;plugin=wsoFarcrytickets&amp;deploy=true">here</a> to deploy it now.</cfoutput>
    <cfabort>
  </cfcatch>
</cftry>
<!--- check if a department exists, else show link to create --->
<cfquery name="ticketdepartmentcheck" datasource="#application.dsn#">
SELECT objectid FROM #application.dbowner#departments WHERE objectid = objectid
</cfquery>
<cfif isdefined('ticketdepartmentcheck.recordcount') and ticketdepartmentcheck.recordcount le 0>
  <cfoutput>There is no Department created yet. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/departments.cfm&plugin=wsoFarcryTickets">here</a> to create one now.</cfoutput>
  <cfabort>
</cfif>
<!--- check if the knowledge base type is deployed, else show link to deploy --->
<cftry>
  <cfset oFormtoolUtil = createObject("component",
"farcry.core.packages.farcry.formtools") />
  <cfset sqlColumns="objectid" />
  <cfset knbase = oFormtoolUtil.getRecordset(sqlColumns=sqlColumns,
sqlWhere="objectid = objectid", typename="knbase",
bCheckVersions=true) />
  <cfcatch type="database">
    <cfoutput>The 'Knowledge Base' content type has not been deployed yet. Click <a href="/webtop/admin/customadmin.cfm?module=customlists/knbase.cfm&amp;plugin=wsoFarcrytickets&amp;deploy=true">here</a> to deploy it now.</cfoutput>
    <cfabort>
  </cfcatch>
</cftry>
<!--- check for and get new tickets from mail server --->
<cfpop action="getALL"
name="mailtickets"
server="#application.config.wsoFarcryTickets.ticketserver#"
port="#application.config.wsoFarcryTickets.ticketservercfpop#"
timeout="#application.config.wsoFarcryTickets.ticketservertim#"
username="#application.config.wsoFarcryTickets.ticketserverus#"
password="#application.config.wsoFarcryTickets.ticketserverpass#">
<!--- if there are new mail server tickets, get them and insert to db --->
<cfif mailtickets.recordcount gt 0>
  <cfoutput query="mailtickets">
    <cfif not listContains(mailtickets.subject, "WSO-Ticket")>
      <!--- setup cftry and cfcatch block to be sure email is not deleted while not inserted to db --->
      <cftry>
        <cfset obj = createObject
('component',application.stcoapi.tickets.typePath) />
        <cfset stprops = {} />
        <cfset stprops.objectid = CreateUUID() />
        <cfset stprops.department = "Support" />
        <cfset stprops.description = mailtickets.body />
        <cfset stprops.priority = "medium" />
        <cfset stprops.status = "open" />
        <cfset stprops.subject = mailtickets.subject />
        <cfset stprops.notification = "email" />
        <cfset stprops.createdby = mailtickets.from />
        <cfset stprops.datetimecreated = mailtickets.date />
        <cfset obj.createData(stProperties=stprops) />
        <!--- after inserting to db delete email from mail server --->
        <cfpop action="delete"
server="#application.config.wsoFarcryTickets.ticketserver#"
port="#application.config.wsoFarcryTickets.ticketservercfpop#"
timeout="#application.config.wsoFarcryTickets.ticketservertim#"
username="#application.config.wsoFarcryTickets.ticketserverus#"
password="#application.config.wsoFarcryTickets.ticketserverpass#"
uid="#mailtickets.UID#">
        <cfcatch type="any">
          <h1>Error while inserting email to db, the operation is aborted</h1>
        </cfcatch>
      </cftry>
    </cfif>
  </cfoutput>
</cfif>
<ft:objectAdmin
	title="Tickets"
	typename="tickets"
	ColumnList="createdby,datetimecreated,datetimelastupdated,lastupdatedby,subject,status,department,priority"
	SortableColumns="createdby,datetimecreated,datetimelastupdated,lastupdatedby,subject,status,department,priority"
	lFilterFields=""
	plugin="wsoFarcryTickets"
	sqlorderby="datetimecreated" />
<admin:footer />
<cfsetting enablecfoutputonly="false">
